package com.jason.campusinn.view;

import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.yuandian.wanna.R;

/**
 * Created by yuandian on 2015/5/27.
 */
public abstract class BillKindPopupWindow extends PopupWindow implements View.OnClickListener {

    private View view;
    private Activity context;
    private TextView tv_cost,tv_cash,tv_income;
    public abstract void setSelected(String title);
    private View mBody;

    public BillKindPopupWindow(Activity context){
        this.context = context;

        //初始化页面
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflater.inflate(R.layout.popup_bill_kind, null);
        tv_cash=(TextView)view.findViewById(R.id.tv_popup_bill_kind_cash);
        tv_cost=(TextView)view.findViewById(R.id.tv_popup_bill_kind_cost);
        tv_income=(TextView)view.findViewById(R.id.tv_popup_bill_kind_income);

        mBody=(View)view.findViewById(R.id.view_popup_body);
        mBody.setOnClickListener(this);
        tv_cost.setOnClickListener(this);
        tv_income.setOnClickListener(this);
        tv_cash.setOnClickListener(this);
        setContentView(view);

        // 设置SelectPicPopupWindow弹出窗体的宽
//        this.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        this.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        this.setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
        // 设置SelectPicPopupWindow弹出窗体可点击
        this.setFocusable(true);
        // 设置SelectPicPopupWindow弹出窗体动画效果
//        this.setAnimationStyle(R.style.popwin_anim_style);
//        实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(0xB0FFFFFF);
//        设置SelectPicPopupWindow弹出窗体的背景
        this.setBackgroundDrawable(dw);
//        this.setBackgroundDrawable(new BitmapDrawable());
        this.setOutsideTouchable(true);
        this.update();
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.tv_popup_bill_kind_cash://提现
                setSelected("提现");
                dismiss();
                break;
            case R.id.tv_popup_bill_kind_cost://支出
                setSelected("支出");
                dismiss();
                break;
            case R.id.tv_popup_bill_kind_income://收入
                setSelected("收入");
                dismiss();
                break;
            case R.id.view_popup_body://点击空白消失
                dismiss();
                break;
        }
    }

}
